// Author  : Morbid
// Time    : 2022/04/30 20:24
// FileName: Main_69.java
// Software: IntelliJ IDEA

package LeetCode;

public class Main_69 {
    //69. x 的平方根
    static int mySqrt(int x) {
        long top = 0;
        long free = x;
        long mid = (top + free) / 2;
        while (free - top > -1) {
            if (mid * mid > x) {
                free = mid - 1;
                mid = (top + free) / 2;
            } else if (mid + mid < x) {
                top = mid + 1;
                mid = (top + free) / 2;
            } else
                return (int) mid;
        }
        return (int) mid;
    }

    public static void main(String[] args) {
        int x = 8;
        System.out.println(mySqrt(x));
    }
}
